<?php
//error_reporting(E_WARNING );
include_once(APP_PATH.'/sms/configs/sms_config.php');
class sms_controller_comment extends Controller{
	/**
	 *
	 * @var sms_model_data
	 */
	var $sms;
	/**
	 * 
	 *
	 * @var sms_model_message
	 */
	var $sms_message;
	/**
	 * 
	 *
	 * @var sms_model_reciever
	 */
	var $sms_reciever;
	
	const ERROR_NO_RECIEVER = 'err_no_reciever';
	
	const TYPE_SYSTEM = 0;
	const TYPE_USER	=	1;
	
	public function __construct($app, $controller){
		parent::__construct($app, $controller);
		$this->comment = new sms_model_comment();
		$this->headerView = $this->rootDir."/views/index/_header.phtml";
		$this->__title = '消息中心';
	}
	
	public function index_action(){
		$this->requireLogin();
		$this->comment_list_action();
	}
	
	public function test_action(){
		$this->requireLogin();
		//$args = array('thread_id'=>'','uid'=>'','app'=>'','control'=>'','act'=>'','rid'=>'','authorid'=>''
		$para = array('thread_id'=>663,'uid'=>5164303,'app'=>'blog','control'=>'index','act'=>'view_thread','rid'=>183,'authorid'=>4892787);
		$rst = sms_util_comment::upCommentLog($para,1);
		var_dump($rst);
	}
	/**
	 * 获取别人对我的留言列表
	 *
	 */
	public function message_list_action(){
		$this->requireLogin();
		$uid = self::$login['uid'];
		$page = _('page', 1);
		$args['app'] = 'index';
		$args['control'] = 'index';
		$args['action'] = 'index';
		$args['page'] = $page;
		$args['pageSize'] = sms_model_message::PAGE_SIZE;
		//获取我别人给我的评论列表
		$ret = $this->comment->getInCommentList($uid,$args,true);
		/*$ret = CacheManager::getInstance()->get(array(
			'app'=>$this->app,
			'func'=>array(
				array($this->comment, 'getInCommentList'), 
				array($uid, $args, false)				
			)
		));*/
		sms_util_comment::setReadedComment($uid,sms_config::MSG_MESSAGE_CNT);
		$pages = $this->genPages($ret['INFO']);
		$this->ret = self::success(array('ret'=>$ret, 'pages'=>$pages));
		$this->view = 'message';
	}
	
	/**
	 * 获取我对别人的留言列表
	 *
	 */
	public function mymessage_list_action(){
		$this->requireLogin();
		$uid = self::$login['uid'];
		$page = _('page', 1);
		$args['app'] = 'index';
		$args['control'] = 'index';
		$args['action'] = 'index';
		$args['page'] = $page;
		$args['pageSize'] = sms_model_message::PAGE_SIZE;
		//获取我别人给我的评论列表
		$ret = $this->comment->getOutCommentList($uid,$args,true);
		/*$ret = CacheManager::getInstance()->get(array(
			'app'=>$this->app,
			'func'=>array(
				array($this->comment, 'getInCommentList'), 
				array($uid, $args, false)				
			)
		));*/
		sms_util_comment::setReadedComment($uid,sms_config::MSG_REMSG_CNT);
		$pages = $this->genPages($ret['INFO']);
		$this->ret = self::success(array('ret'=>$ret, 'pages'=>$pages));
		$this->view = 'mymessage';
	}
	
	/**
	 * 获取别人对我的评论列表
	 *
	 */
	public function comment_list_action(){
		$this->requireLogin();
		$uid = self::$login['uid'];
		$page = _('page', 1);
		$args['page'] = $page;
		$args['pageSize'] = sms_model_message::PAGE_SIZE;
		//获取我别人给我的评论列表
		$ret = $this->comment->getInCommentList($uid,$args,false);
/*		$ret = CacheManager::getInstance()->get(array(
			'app'=>$this->app,
			'func'=>array(
				array($this->comment, 'getInCommentList'), 
				array($uid, $args, false)				
			)
		));*/
//		var_dump($ret['ROWS'])
		sms_util_comment::setReadedComment($uid,sms_config::MSG_COMMENT_CNT);
		$pages = $this->genPages($ret['INFO']);
		$this->ret = self::success(array('ret'=>$ret, 'pages'=>$pages));
		$this->view = 'comment';
	}
	
	/**
	 * 获取别人对我的评论列表
	 *
	 */
	public function mycomment_list_action(){
		$this->requireLogin();
		$uid = self::$login['uid'];
		$page = _('page', 1);
		$args['page'] = $page;
		$args['pageSize'] = sms_model_message::PAGE_SIZE;
		//获取我别人给我的评论列表
		$ret = $this->comment->getOutCommentList($uid,$args,false);
		/*$ret = CacheManager::getInstance()->get(array(
			'app'=>$this->app,
			'func'=>array(
				array($this->comment, 'getInCommentList'), 
				array($uid, $args, false)				
			)
		));*/
		sms_util_comment::setReadedComment($uid,sms_config::MSG_RECOM_CNT);
		$pages = $this->genPages($ret['INFO']);
		$this->ret = self::success(array('ret'=>$ret, 'pages'=>$pages));
		$this->view = 'mycomment';
	}
	
}
